<template>
  <div>
    <el-dialog title="查看详情" width="800px" class="icon-dialog" :visible.sync="show" :before-close="closeForm"
      append-to-body @open="open">
      <el-form ref="form" :size="size" :model="form" :label-width="$store.getters.device !== 'mobile'?'18%':'90px'">
        <div class="table-bordered">
          <el-row>
            <el-col>
              <table class="table table-bordered" width="100%" style="word-break:break-all; font-size:13px;">
                <tbody>
                  <tr>
                    <td class="title" width="100">订单编号：</td>
                    <td>
                      {{ form.orderInfo.order_num_alias }}
                    </td>
                  </tr>
                  <tr>
                    <td class="title" width="100">下单用户：</td>
                    <td>
                      {{ form.orderInfo.member.nickname }}
                    </td>
                  </tr>
                  <tr>
                    <td class="title" width="100">下单时间：</td>
                    <td>
                      {{ form.orderInfo.create_time }}
                    </td>
                  </tr>
                  <tr>
                    <td class="title" width="100">预约时间：</td>
                    <td>
                      {{ form.orderInfo.ServiceTime }}
                    </td>
                  </tr>
                  <tr>
                    <td class="title" width="100">订单状态：</td>
                    <td>
                      {{ form.orderInfo.orderStatus.name }}
                    </td>
                  </tr>
                  <tr>
                    <td class="title" width="100">支付方式：</td>
                    <td>
                      {{ form.orderInfo.paymethod.title }}
                    </td>
                  </tr>
                  <tr v-if="form.orderInfo.order_status_id==1">
                    <td class="title" width="100">扫码支付：</td>
                    <td>
                      <img width="200" style="padding: 0;margin: 0;" :src="form.orderInfo.payqrcode" />
                    </td>
                  </tr>
                  <tr>
                    <td class="title" width="100">支付时间：</td>
                    <td>
                      {{ form.orderInfo.pay_time }}
                    </td>
                  </tr>
                  <tr>
                    <td class="title" width="100">订单金额：</td>
                    <td>
                      {{ form.orderInfo.total }}
                    </td>
                  </tr>
                  <tr v-if="form.orderInfo.additional>0">
                    <td class="title" width="100">订单尾款：</td>
                    <td>
                      <el-input v-model="form.orderInfo.additional" auto-complete="off" clearable
                        placeholder="请输入订单尾款" />
                    </td>
                  </tr>
                  <tr>
                    <td class="title" width="100">服务地址：</td>
                    <td>
                      <div>联系人：{{ form.orderInfo.address.name }} {{ form.orderInfo.address.telephone }}</div>
                      <div>地 址：{{ form.orderInfo.address.alladdress }}</div>
                    </td>
                  </tr>
                  <tr>
                    <td class="title" width="100">订购的服务：</td>
                    <td>
                      <div v-for="(item, index) in form.goods" :key="index">
                        <div class="image__preview">
                          <el-image v-if="item.image" class="table_list_pic" :src="item.image"
                            :preview-src-list="[item.image]" />
                        </div>
                        <div class="goodsdetailtext">
                          <div>{{ item.name+'\n' }}</div>
                          <div v-if="item.sku">{{ item.sku+'\n' }}</div>
                          <div v-if="item.customtext">{{ item.customtext+'\n' }}</div>
                          <div>数量：{{ item.quantity }}</div>
                          <div>小计：{{ item.total }}</div>
                        </div>
                      </div>
                    </td>
                  </tr>
                  <tr>
                    <td class="title" width="100">订单备注：</td>
                    <td>
                      <div>{{ form.orderInfo.remark }}</div>
                      <div v-for="(scr, index) in form.orderInfo.OrderImage" :key="index">
                        <div class="image__preview">
                          <el-image v-if="scr" class="table_list_pic" :src="scr" :preview-src-list="[scr]" />
                        </div>
                      </div>
                    </td>
                  </tr>
                </tbody>
              </table>
            </el-col>
          </el-row>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="closeForm">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  import ImagesUpload from '@/components/common/ImagesUpload.vue'
  export default {
    name: 'Orderdetail',
    components: {
      ImagesUpload
    },
    props: {
      show: {
        type: Boolean,
        default: false
      },
      size: {
        type: String,
        default: 'mini'
      },
      info: {
        type: Object
      }
    },
    data() {
      return {
        form: {
          orderInfo: {
            orderStatus: {},
            address: {},
            paymethod: {},
            member: {}
          }
        },
        loading: false
      }
    },
    watch: {
      show(val) {}
    },
    methods: {
      open() {
        this.form = this.info
      },
      submit() {
        this.$refs['form'].validate(valid => {
          if (valid) {
            this.loading = true
            this.$api.post('/order/update', this.form).then(res => {
              this.$message({
                message: res.msg,
                type: 'success'
              })
              this.$emit('refesh_list')
              this.closeForm()
            }).catch(() => {
              this.loading = false
            })
          }
        })
      },
      closeForm() {
        this.$emit('update:show', false)
        this.loading = false
        if (this.$refs['form'] !== undefined) {
          this.$refs['form'].resetFields()
        }
      }
    }
  }
</script>
<style>
  .image__preview {
    float: left;
    padding-right: 5px;
  }

  .goodsdetailtext {
    float: left;
    padding-left: 5px;
  }

  .table_list_pic {
    width: 60px;
    height: 60px;
  }
</style>
